{% extends 'kingadmin/table_index.html' %}
{% load tags %}


    {% block container %}
        <div class="panel panel-info">
            <div class="panel-heading">
                <h3 class="panel-title">{% get_model_name admin_class %}
                {% if not admin_class.readonly_table %}
                <a href="{{ request.path }}add/" class="pull-right">Add</a>
                {% endif %}
                </h3>
            </div>
            <div class="panel-body">
                <div class="row">
                    <form class="" method="get">
                        <div class="row">
                            <div class="col-lg-2">
                                <input type="search" class="form-control" name="_q" placeholder="搜索" style="margin-left: 15px;margin-bottom: 10px" value={{ search_key }}>
                            </div>
                            <div class="col-lg-2">
                                <button type="submit" class="btn btn-info" style="margin-left: 10px;margin-bottom: 10px">搜索</button>
                            </div>
                        </div>
                        <div class="row" style="margin-left: 1px">
                        {% for filter_field in admin_class.list_filters %}
                            <div class="col-lg-2">
                                <span>{{ filter_field }}</span>
                                {% render_fileter_ele filter_field admin_class filter_conditions %}
                            </div>
                        {% endfor %}
                        <button type="submit" class="btn btn-info" style="margin-top: 20px;margin-left: 10px">筛选</button>
                        </div>
                    </form>

                    <form onsubmit="return ActionSubmit(this)" method="POST">{% csrf_token %}
                        <div class="row" style="margin-left: 1px;margin-top: 20px">
                            <div class="col-lg-2">
                                <select id="action_list" name="action" class="form-control">
                                    <option value="">------</option>
                                    {% for action in admin_class.actions %}
                                        <option value="{{ action }}">{% get_action_name admin_class action %}</option>
                                    {% endfor %}
                                </select>
                            </div>
                            <button type="submit" class="btn btn-default" style="margin-left: 15px">执行</button>
                        </div>
                    </form>

                </div>

                <table class="table table-hover">
                    <thead>
                    <tr>
                        <th style="width: 10px"><input type="checkbox" tag="fa_checkbox" onclick="CheckAllToggle(this)"></th>
                        {% for column in admin_class.list_display %}
                            {% build_table_header_column column orderby_key filter_conditions admin_class %}
{#                        <th><a href="?o={{ column }}">{{ column }}</a></th>#}
                        {% endfor %}
                    </tr>
                    </thead>
                    <tbody>
{#                    {% get_query_sets  admin_class as query_sets %}#}
                    {%  for obj in query_sets %}
                    <tr>
                        <td><input tag="obj_checkbox" type="checkbox" value="{{ obj.id }}" onclick="CheckOneToggle(this)"></td>
                        {% build_table_row request obj admin_class %}
                    </tr>
                    {% endfor %}
                    </tbody>
                </table>



             <div class="row" style="margin-left: 5px">
                            共查询到 {{ query_sets.paginator.count }} 条数据
             </div>
            <nav>
              <ul class="pagination">
                  {% if query_sets.has_previous %}
{#                      <li class=""><a href="?page=1">首页</a></li>#}
                      <li class=""><a href="?page={{ query_sets.previous_page_number }}&{% filters_cn filter_conditions previous_orderby search_key %}">上页</a></li>
                  {% endif %}

{#                  {% for loop_counter in query_sets.paginator.page_range %}#}
{#                    {% render_page_ele loop_counter query_sets filter_conditions %}#}
{#                  {% endfor %}#}

                  {% build_paginators query_sets filter_conditions previous_orderby search_key%}


                  {% if query_sets.has_next %}
                      <li><a href="?page={{ query_sets.next_page_number }}&{% filters_cn filter_conditions previous_orderby search_key %}">下页</a></li>
{#                      <li class=""><a href="?page={{ query_sets.paginator.num_pages }}">尾页</a></li>#}
                  {% endif %}
              </ul>
            </nav>


            </div>
        </div>

        <script>
        function CheckAllToggle(ele) {
            if ($(ele).prop("checked")){
                $("input[tag='obj_checkbox']").prop("checked",true)
            }else {
                $("input[tag='obj_checkbox']").prop("checked",false);
            }
        }

        function CheckOneToggle(ele) {
            if ($(ele).prop("checked")==false){
                $("input[tag='fa_checkbox']").prop("checked",false);
            }
        }

        function ActionSubmit(from_ele) {
            var selected_ids = [];
            $("input[tag='obj_checkbox']:checked").each(function () {
                selected_ids.push($(this).val())
            });
            var select_action = $("#action_list").val();
            if (selected_ids.length == 0){
                alert("请先选择数据！")
                return
            }
            if (select_action.length == 0){
                alert("未选择执行方法")
            }

            // start submit
            var selected_ids_ele = "<input name='selected_ids' type='hidden' value='" + selected_ids.toString() + "'>"
            $(from_ele).append(selected_ids_ele);

            return true;
        }
        </script>
    {% endblock %}

    {#<div id="qb-sougou-search" style="display: none; opacity: 0;"><p>搜索</p><p class="last-btn">复制</p><iframe src="./Dashboard Template for Bootstrap_files/saved_resource.html"></iframe></div></body>#}
